<%-- 
    Document   : Hotels
    Created on : Nov 1, 2011, 11:50:41 PM
    Author     : Mr-aUgust
--%>

<%@page pageEncoding="UTF-8"%>
<%@ page language="java" import="javazoom.upload.*,java.util.*" %>
<%@ page session="true" import="java.util.Collection,DAL.*" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="/WEB-INF/taglib139.tld" prefix="pg" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f" %>
<!DOCTYPE html>
<%
        String im="";
        try{
        if (MultipartFormDataRequest.isMultipartFormData(request))
                      {
                         MultipartFormDataRequest mrequest = new MultipartFormDataRequest(request);
                         UploadBean upBean=new UploadBean();
                         upBean.setFolderstore(getServletContext().getRealPath("/") + "images\\Hotel");
                         String todo = null;
                         if (mrequest != null) todo = mrequest.getParameter("todo");
                             if ( (todo != null) && (todo.equalsIgnoreCase("upload")) )
                             {
                                Hashtable files = mrequest.getFiles();
                                if ( (files != null) && (!files.isEmpty()) )
                                {
                                    UploadFile file = (UploadFile) files.get("uploadfile");
                                    if (file != null) //out.println("<li>Form field : uploadfile"+"<BR> Uploaded file : "+file.getFileName()+" ("+file.getFileSize()+" bytes)"+"<BR> Content Type : "+file.getContentType());
                                    // Uses the bean now to store specified by jsp:setProperty at the top.
                                        im="images/Hotel/"+file.getFileName();
                                    upBean.store(mrequest, "uploadfile");
                                  //  out.println("<li> uploaded files success");
                                  //  out.println(getServletContext().getRealPath("/")+ "images\\car");
                                }
                                else
                                {
                                  out.println("<li>No uploaded files");
                                }
                             }
                   else out.println("<BR> todo="+todo);
                  }
            }catch (Exception ex){}
 %>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>East2West Tours and Travels</title>
         <script src="../js/jqueryvalidate.js" type="text/javascript"></script>
        <script src="../js/jquery.validate.js" type="text/javascript"></script>
        <script src="../js/gen_validatorv4.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(document).ready(function() {
            $("#FormUpload").validate
                ({
                    rules:{
                        uploadfile:{ required: true}
                    },
                    messages: {
                        uploadfile:{required:"*"}   
                        }            
                });   
                
            });
            $(document).ready(function() {
            $("#formhotel").validate
                ({
                    rules:{
                        nameimage:{required: true},
                        hotelname:{ required: true},
                        address:{ required: true},
                        price:{ required: true}
                    },
                    messages: {
                        nameimage:{required: "Please choose a image upload."},
                        hotelname:{required:"*"},
                        address:{ required:"*"},
                        price:{ required:"*"}
                        }            
                });   
                
            });
            $(document).ready(function() {
            $("#formedithotel").validate
                ({
                    rules:{
                        hotelname:{ required: true},
                        address:{ required: true},
                        price:{ required: true}
                    },
                    messages: {
                        hotelname:{required:"*"},
                        address:{ required:"*"},
                        price:{ required:"*"}
                    }            
                });   
                
            });
         </script>
       <style type="text/css">
           .khunvien
           {
                width:630px;
                height:500px;
                background-color:#f0f3ec;
                margin-top:0px;
           }
           #Table
            {
            border:1px solid green;
            }
            th
            {
            border:1px solid green;
            background-color:green;
            color:white;
            }
            .td
            {
            border:1px solid green;
            }
            .font
            {
            font-family:"Times New Roman", Times, serif;
            font-size:x-large;
            font-weight:bold;
            width:200px;
            margin-left:auto;
            margin-right:auto;
            color:#0707e7;
            }
            #reset
            {
            width:120px;
            }
            #list
            {
            width:150px;
            }
            .sizeedit
            {
                width:50px;
            }
        </style>
    </head>
    <body>
        
        <div class="khunvien">
            <%
                session.removeAttribute("status");
               String image="",status="",hotelID="",namecyti="",hotelname="",address="",standard="",price="";
                if(session.getAttribute("statusH")==null)
                {            
                 LocationBean lcbean=new LocationBean();
                 Collection cl=lcbean.ListLocation();
                 request.setAttribute("lc1",cl);
            %>
            <form action="management.jsp?page=Hotels" method="post" name="FormUpload" id="FormUpload" enctype="multipart/form-data">
                <table border="0" width="630px">
                    <tr>
                        <td></td>
                        <td align="left" class="font">Create Hotel</td> 
                    </tr>   
                    <tr>
                        <td colspan="2" height="20px"></td>
                    </tr>
                   <tr>
                    <td width="40px">Choose Image:</td>
                    <td width="100px" style="color:red;">
                            <input type="file" name="uploadfile" id="uploadfile" size="25">
                            <input type="hidden" name="todo" value="upload">
                            <input type="submit" name="Submit" value="Upload">  
                    </td>
                    <tr>
                        <td colspan="2" align="center">
                            <div style="color:red;" id="FormUpload_uploadfile_errorloc" class="error_strings"></div>
                        </td>
                    </tr>
                   
                </table>
            </form>
             <script type="text/javascript">
            var frmuploadvalidator  = new Validator("FormUpload");
            frmuploadvalidator.EnableOnPageErrorDisplay();
            frmuploadvalidator.EnableMsgsTogether(); 
            frmuploadvalidator.addValidation("uploadfile","file_extn=jpg;gif;png","Allowed files types are: jpg;gif;png");
        </script>
            <form action="../ControllerHotels" method="post" name="formhotel" id="formhotel">
                <table class="table" border="0" cellpadding="2" cellspacing="2" width="630px" >
                  <tr>
                        <td></td>
                        <td style="color:red;">
                           <% if(im !="")
                            {
                           %>
                                <img src="../<%=im%>"  width="100px" height="100px" />
                                <input type="hidden" name="image" value="<%=im%>" /> 
                            <%
                            }
                            %>
                            <input type="hidden" name="nameimage" value="<%=im%>" />
                        </td>
                    </tr>
                    <tr>
                        <td width="30px">Name City:</td>
                        <td width="100px" style="color:red;">
                            <select name="location" id="list">
                                <c:forEach items="${lc1}" var="lction">
                                    <option value="${lction.locationID}">${lction.namecity}</option>
                                </c:forEach>
                            </select>
                            <div style="color:red;" id='formhotel_location_errorloc' class="error_strings"></div>
                        </td>
                    </tr>    
                    <tr>
                        <td>Hotel Name</td>
                        <td style="color:red;">
                            <input type="text" name="hotelname" size="40" />
                        </td>
                    </tr>
                    <tr>
                        <td>Address</td>
                        <td style="color:red;">
                            <textarea cols="30" rows="3" name="address"></textarea>
                        </td>
                    </tr>
                    <tr>
                        <td>Standard:</td>
                        <td style="color:red;">
                            <select name="standard" id="list">
                                <option value="2 star">2 star</option>
                                <option value="3 star">3 star</option>
                                <option value="4 star">4 star</option>
                                <option value="5 star">5 star</option>
                                <option value="other">other</option>
                            </select>
                            <div style="color:red;" id='formhotel_standard_errorloc' class="error_strings"></div>
                        </td>
                    </tr>
                     <tr>
                        <td>Price:</td>
                        <td style="color:red;">
                            <input type="text" name="price" size="40" />
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2" height="10px"></td>
                    </tr>
                    <tr>
                        <td></td>
                        <td><input type="submit" name="createhotel" value="Create Hotel"/><input id="reset" type="reset" value="Reset"  /></td>
                    </tr>
                </table>
            </form>
            <%
            }
               else
                   {
                     hotelID=session.getAttribute("hotelID").toString();
                     image= session.getAttribute("image").toString();
                     namecyti=session.getAttribute("nameCity").toString();
                     hotelname=session.getAttribute("hotelName").toString();
                     address=session.getAttribute("address").toString();
                     standard=session.getAttribute("standard").toString();
                     price=session.getAttribute("price").toString();
                     
                     LocationBean lcbb=new LocationBean();
                     Collection collec=lcbb.SelectLocationEdit(namecyti);
                     request.setAttribute("uht",collec);
            %>
                <form action="management.jsp?page=Hotels" method="post" name="FormUploadEdit" id="FormUploadEdit" enctype="multipart/form-data">
                <table border="0" width="630px">
                    <tr>
                        <td></td>
                        <td align="left" class="font">Edit Hotel</td> 
                    </tr>   
                    <tr>
                        <td colspan="2" height="20px"></td>
                    </tr>
                   <tr>
                    <td width="30px">Choose Image:</td>
                    <td width="100px" align="left" style="color:red;">
                            <input type="file" name="uploadfile" id="uploadfile" size="25">
                            <input type="hidden" name="todo" value="upload">
                            <input type="submit" name="Submit" value="Upload">  
                    </td>
                    <tr>
                        <td colspan="2" align="center">
                            <div style="color:red;" id="FormUploadEdit_uploadfile_errorloc" class="error_strings"></div>
                        </td>
                    </tr>
                   
                </table>
              </form>
               <script type="text/javascript">
                  var frmuploadvalidator  = new Validator("FormUploadEdit");
                  frmuploadvalidator.EnableOnPageErrorDisplay();
                  frmuploadvalidator.EnableMsgsTogether(); 
                  frmuploadvalidator.addValidation("uploadfile","file_extn=jpg;gif;png","Allowed files types are: jpg;gif;png");
              </script>
                <form action="../ControllerHotels" method="get" name="formedithotel" id="formedithotel">
                <table class="table" border="0" cellpadding="2" cellspacing="2" width="630px" >

                    <tr>
                        <td></td>
                        <td>
                           <% if(im !="")
                            {
                           %>
                                <img src="../<%=im%>"  width="150px" height="100px" />
                                <input type="hidden" name="image" value="<%=im%>" />
                            <%
                            }
                            else
                                {
                                %>                            
                                <img src="../<%=image%>"  width="150px" height="100px" />
                                <input type="hidden" name="imageDB" value="<%=image%>" />                            
                                <%
                                }
                            %>
                        </td>
                    </tr>
                    <tr>
                        <td>Hotel ID:</td>
                        <td><input type="hidden" name="hotelId" value="<%=hotelID%>" /><label><b><%=hotelID%></b></label></td>
                    </tr>
                    <tr>
                        <td width="30px">Location Name:</td>
                        <td width="100px" style="color:red;">
                            <select name="location" id="location">
                                <option value="0">--choose location--</option>
                                <c:forEach items="${uht}" var="ht">
                                    <option value="${ht.locationID}" ${ht.editDrop}>${ht.namecity}</option>
                                </c:forEach>
                            </select>
                            <div style="color:red;" id='formedithotel_location_errorloc' class="error_strings"></div>
                        </td>
                    </tr>    
                    <tr>
                        <td>Hotel Name</td>
                        <td style="color:red;">
                            <input type="text" name="hotelname" size="40" value="<%=hotelname%>" />
                        </td>
                    </tr>
                    <tr>
                        <td>Address</td>
                        <td style="color:red;">
                            <textarea cols="30" rows="3" name="address"><%=address%></textarea>
                        </td>
                    </tr>
                    <tr>
                        <td>Standard:</td>
                        <td style="color:red;">
                            <select name="standard" id="standard">
                                <%
                                    if(standard.equals("2 star"))
                                        {
                                        %>
                                          <option value="2 star">2 star</option>
                                          <option value="3 star">3 star</option>
                                          <option value="4 star">4 star</option>
                                          <option value="5 star">5 star</option>
                                          <option value="other">other</option>
                                          <%
                                        }
                                        else if(standard.equals("3 star"))
                                        {
                                        %>
                                          <option value="3 star">3 star</option>
                                          <option value="2 star">2 star</option>
                                          <option value="4 star">4 star</option>
                                          <option value="5 star">5 star</option>
                                          <option value="other">other</option>
                                        <%
                                        }
                                        else if(standard.equals("4 star"))
                                        {
                                        %>
                                          <option value="4 star">4 star</option>
                                          <option value="2 star">2 star</option>
                                          <option value="3 star">3 star</option>                                            
                                          <option value="5 star">5 star</option>
                                          <option value="other">other</option>
                                        <%
                                         }
                                       else if(standard.equals("5 star"))
                                        {
                                        %>
                                          <option value="5 star">5 star</option>
                                          <option value="2 star">2 star</option>
                                          <option value="3 star">3 star</option>
                                          <option value="4 star">4 star</option>                                            
                                          <option value="other">other</option> 
                                       <%
                                        }
                                        else
                                            {
                                            %>
                                             <option value="other">other</option> 
                                             <option value="2 star">3 star</option>
                                             <option value="3 star">3 star</option>
                                             <option value="4 star">4 star</option>
                                             <option value="5 star">4 star</option>                                            
                                             
                                            <%
                                            }
                                %>
                            </select>
                            <div style="color:red;" id='formedithotel_standard_errorloc' class="error_strings"></div>
                        </td>
                    </tr>
                     <tr>
                        <td>Price:</td>
                        <td style="color:red;">
                            <input type="text" name="price" size="40" value="<%=price%>" />
                        </td>
                    </tr>
                    <tr>
                        <td colspan="2" height="10px"></td>
                    </tr>
                    <tr>                        
                        <td><input type="submit" name="updatehotel" value="Update Hotel"/></td>
                        <td>
                          <form action="../ControllerHotels" method="post">
                             <input id="cancelupdate" type="submit" name="reset" value="Cancel Update"  />
                         </form>
                        </td>
                    </tr>
                </table>
           </form>
            <%
                }
            %>
        </div>
         <br>
        <%
        HotelBean cb=new HotelBean();
        Collection cl1=cb.ListHotel();
        request.setAttribute("lc",cl1);
        %>
        <div class="font">List Hotel</div>    
        <table width="100%" id="Table">  
            <tr>
                <th>ID</th>
                <th>Image</th>
                <th>Name City</th>
                <th>HotelName</th>
                <th>Address</th>
                <th>Standard</th>
                <th>Price</th>
                <th>Edit</th>
                <th>Delete</th>
            </tr>
            <pg:paging pageSize="5" url="management.jsp?page=Hotels">
                <c:forEach items="${lc}" var="cr">
                    <pg:item>
                        <tr>
                            <td class="td">${cr.hotelID}</td>
                            <td class="td"><img src="../${cr.image}" width="50px" height="50px" /></td>
                            <td class="td">${cr.nameCity}</td>
                            <td class="td">${cr.hotelName}</td>
                            <td class="td">${cr.address}</td>
                            <td class="td">${cr.standard}</td>
                            <td class="td"><f:formatNumber value="${cr.price}" pattern="$#,###"/> </td>
                            <td class="td" width="30px">
                                <form action="../ControllerHotels" method="post">
                                    <input type="hidden" name="hotelID" value="${cr.hotelID}" />
                                    <input type="hidden" name="image" value="${cr.image}" />
                                    <input type="hidden" name="nameCity" value="${cr.nameCity}" />
                                    <input type="hidden" name="hotelName" value="${cr.hotelName}" />
                                    <input type="hidden" name="address" value="${cr.address}" />
                                    <input type="hidden" name="standard" value="${cr.standard}" />
                                     <input type="hidden" name="price" value="${cr.price}" />
                                    <input type="submit" class="sizeedit" name="edit" value="Edit"/>
                                </form>
                            </td>
                            <td class="td" width="40px">
                                <form action="../ControllerHotels" method="post">
                                    <input type="hidden" name="hotelID" value="${cr.hotelID}" />
                                    <input type="submit" name="delete" value="Delete" OnClick="return confirm('Are you sure you want delete record this?');"/>
                                </form>
                            </td>
                        </tr>
                    </pg:item>       
                </c:forEach>
                <pg:index>
                    <pg:page><%=thisPage%></pg:page>
                </pg:index>
            </pg:paging>
        </table>
       
    </body>
</html>

